<%@ page import="com.wuchao.service.serviceImpl.ServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>

    </style>
</head>
<body>
<script src="../js/jquery.js"></script>
<script>
<%
    response.setCharacterEncoding("utf-8");
    //先拿op
    String op = request.getParameter("op");
    if(op!=null){//旁段拿值，
        ServiceImpl service = new ServiceImpl();
        if(op.equals("delete")){//delete 删除
             int id=  Integer.parseInt(request.getParameter("id")) ;
             //接住id
             int update = service.update("delete from user where id=? ",id);//进行删除
             if(update>0){//删除成功
                 request.getRequestDispatcher("main.jsp?isdelete1=true").forward(request,response);
             }else{
                 response.sendRedirect("main.jsp?isdelete2=true");
             }
        }else if(op.equals("add")){//
            String name = request.getParameter("name");
             int sex=  Integer.parseInt(request.getParameter("sex")) ;
              String hobby = request.getParameter("hobby");
             //接住id
             int update = service.update("insert user(name,sex,hobby) values(?,?,?) ",name,sex,hobby);//进行删除
             if(update>0){//增加成功
                 request.getRequestDispatcher("main.jsp?isadd1=true").forward(request,response);
             }else{
                 response.sendRedirect("main.jsp?isadd2=true");
             }
        }else if(op.equals("update1")){//先旁段修改操作
            int id=  Integer.parseInt(request.getParameter("id")) ;
                 request.getRequestDispatcher("update.jsp?id="+id).forward(request,response);
        }else if(op.equals("update2")){//
             int id=  Integer.parseInt(request.getParameter("id")) ;
            String name = request.getParameter("name");
             int sex=  Integer.parseInt(request.getParameter("sex")) ;
              String hobby = request.getParameter("hobby");
             //接住id
             int update = service.update("update user set name=?,sex=?,hobby=? where id=? ",name,sex,hobby,id);//进行删除
             if(update>0){//修改成功
                 request.getRequestDispatcher("main.jsp?isupdate1=true").forward(request,response);
             }else{
                 response.sendRedirect("main.jsp?isupdate2=true");
             }
        }
    }else{
        response.sendRedirect("main.jsp?feifa=t");//非法入侵
    }
%>
</script>
</body>
</html>
